{extends file="../home.html"}
{block name="title"}{$head_title}{/block}

{block name="css"}
<link href="__PUBLIC__/Css/front/css/publish_post.css?version={$version}" type="text/css" rel="stylesheet">
{/block}
{block name="content"}

	
	<div class="com_header">
		<a href="javascript:;" class="go_back"><i class="icon_back"></i></a>发帖
	</div>
	<form>
		<div class="reply" style="margin-top: 2.2rem">
			{include file="./common_post.html"}
			{if $opt == 'praise'}
				{include file="./praise_hide.html"}
			{/if}
		</div>
			{if $opt == 'praise'}
				{include file="./praise_price.html"}
			{elseif $opt == 'reward'}
				{include file="./reward_price.html"}
			{elseif $opt == 'crowdfunding'}
				{include file="./crowdfunding_price.html"}
			{/if}
	</form>
	
	{if $opt == 'reward'}
		<div class="tips">
			1、请在5天内采纳一个“最佳答案”<br>
			2、如果5天内无人回答，您可以申请退款<br>
			3、所有围观用户的消耗将有50%分配给您，另50%计入到赏金总额。<br>
		</div>
	{/if}

	<div class="fixed_bot" id="post"> 
		发表
	</div>
{/block}
{block name="js"}


<script type="text/javascript">
	var uptoken = $('#uptoken').val()
var image_domain = $('#image_domain').val();
var channel_id = parseInt('{$channel_id}');
var posting = false;
// if(!is_ios()){
//     $("input[name=file]").attr({
//         'capture':'camera',
//         'accept':'image/*'
//     });
// }
</script>


<script type="text/javascript" src="__JS__/plupload_js/moxie.min.js"></script>
<script type="text/javascript" src="__JS__/plupload_js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="__JS__/plupload_js/plupload.min.js"></script>

<script type="text/javascript" src="__JS__/qiniu.js"></script>

{if $opt == 'normal'}
<script src="/Public/Js/front/js/post_tiezi.js"></script>
{elseif $opt == 'praise'}
<script src="/Public/Js/front/js/post_zs.js"></script>
{elseif $opt == 'reward'}
<script src="/Public/Js/front/js/post_xs.js"></script>
{elseif $opt == 'crowdfunding'}
<script src="/Public/Js/front/js/post_zc.js"></script>
{/if}

<script>

{literal}

//七牛多图上传
 var uploader = new plupload.Uploader({
        runtimes : 'html5',
        browse_button : 'upload_btn', //触发文件选择对话框的按钮，为那个元素id
        url : 'http://up.qiniu.com/', //服务器端的上传页面地址
        flash_swf_url : '/Public/Js/plupload_js/Moxie.swf',//swf文件，当需要使用swf方式进行上传时需要配置该参数
        silverlight_xap_url : '/Public/Js/plupload_js/Moxie.xap', //silverlight文件，当需要使用silverlight方式进行上传时需要配置该参数
        filters : {
            // 设置大小
            max_file_size : '10mb',
            // 允许上传的类型
           mime_types: [
             // {title : "Image files", extensions : "png,jpeg,gif,bmp,jpg"},
           ]
        },
        multipart: true,
          //设置post传给七牛的token
          multipart_params: {
           'token': uptoken, 
          },
          //修改post字段为七牛的file
          file_data_name: 'file',
          init: {
                PostInit: function() {

                    console.log("upload init");
                    console.log($('.moxie-shim').children())
                    if(!is_ios()){
                        $("input[type=file]").attr({
                            'capture':'camera',
                            'accept':'image/*'
                        });
                    }
                },
                FilesAdded: function(up, files) {

                    //选择文件后直接上传， 或可改成点击按钮上传
                    uploader.start();
                },
                UploadProgress: function(up, file) {

                },
                FileUploaded: function(up, file, info) {
                   console.log(info)
                    // var res = $.parseJSON(info);  
                    // var res = eval('"'+info+'"');  
                    var res = info.response;
                    console.log(res)
                    var r = eval('('+res+')');
                    console.log(r);
                    var sourceLink = image_domain + r.key; //获取上传成功后的文件的Url  
                    var  html = '<li><img src="'+sourceLink+'?imageView2/1/w/200/h/200/imageslim" alt="" data-link="'+sourceLink+'"><span class="del_img" onclick="del_img(this)"></span></li>';
                            
                            var container = $('#img_list1');

                            container.append(html);
                            console.log('finish');
                            var imgs = $('#upload_btn').siblings('.img_url').val();
                            imgs += ','+sourceLink;
                            $('#upload_btn').siblings('.img_url').val(imgs);
                },
                UploadComplete: function(up, files) {
                    // Called when all files are either uploaded or failed
                    console.log('[完成]');
                },
                Error: function(up, err) {
                    // alert(err.response);
                }
            } 
    });  

	uploader.init();
    if(!is_ios()){
        $("input[type=file]").attr({
            'capture':'camera',
            'accept':'image/*'
        });
    }
	// uploader.bind('FilesAdded',function(uploader,files){
	// 	console.log(1111)
	//  	uploader.start(); //上传
        
 //    });
 //    uploader.bind('UploadProgress',function(uploader,file){
 //        //每个事件监听函数都会传入一些很有用的参数，
 //        //我们可以利用这些参数提供的信息来做比如更新UI，提示上传进度等操作
 //    });
 //    uploader.bind('FileUploaded',function(up, file, info){
 //    	console.log(info)
 //    	// var res = $.parseJSON(info);  
 //    	// var res = eval('"'+info+'"');  
 //    	var res = info.response;
 //    	console.log(res)
 //    	var r = eval('('+res+')');
 //    	console.log(r);
 //        var sourceLink = image_domain + r.key; //获取上传成功后的文件的Url  
 //        var  html = '<li><img src="'+sourceLink+'?imageMogr2/auto-orient/thumbnail/!50p/imageslim" alt="" data-link="'+sourceLink+'"><span class="del_img" onclick="del_img(this)"></span></li>';
                
 //                var container = $('#img_list1');

 //                container.append(html);
 //                console.log('finish');
 //                var imgs = $('#upload_btn').siblings('.img_url').val();
 //                imgs += ','+sourceLink;
 //                $('#upload_btn').siblings('.img_url').val(imgs);
 //        //每个事件监听函数都会传入一些很有用的参数，
 //        //我们可以利用这些参数提供的信息来做比如更新UI，提示上传进度等操作
 //    });
function del_img(obj){
	var obj_init = $(obj);
    obj_init.parent().remove();
    var imgs = '';
    $('#img_list1 li').each(function(){
    	imgs += $(this).find('img').data('link');
    })
    $('#img_url').val(imgs)
}




$(function(){


$('.money').on('click',function(){
	$(this).addClass('active').siblings().removeClass('active')
})



// $('.fixed_bot').on('click',function(){
// 	var title = $('#title').val();
// 	if(!title){
// 		alert('请输入标题');
// 		return 
// 	}
// })

	
// function upload_image(obj){
// 	var token = $("#uptoken").val();
// 	var image_domain = $("#image_domain").val();

// 	if ($(obj)[0].files.length > 0 && token != "") {
//         // uploader();
//     } else {
//         layer.open({
//         	title:false,
//         	content:"请选择图片",
//         	btn:["确定"]
//         });
//     }
// }

})
// $("#upload_btn").on("click", function(){
// 	return $("#uploader").click();
// });



{/literal}
</script>

{/block}